package com.gm.commonlib.manger;

import android.app.Activity;
import java.util.ArrayList;
import java.util.List;

public class ActivityMangers {
    private static ActivityMangers activityMangers;
    private List<Activity> activities = new ArrayList<>();

    public static ActivityMangers getActivityMangers() {
        if (activityMangers == null) {
            activityMangers = new ActivityMangers();
        }
        return activityMangers;
    }

    public void addActivity(Activity activity) {
        if (activities != null) {
            activities.add(activity);
        }

    }

    public void removeActivity(Activity activity) {
        if (activities != null) {
            activities.remove(activity);
        }

    }

    public void cleanAllActivity() {
        try{
            if (activities != null) {
                for (Activity activity : activities) {
                    if (activity != null) {
                        activity.finish();
                    }
                }
            }
            activities.clear();
        }
        catch (Exception e){

        }

    }
}
